<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/common.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">src/caffe</a> - common.cpp<span style="font-size: 80%;"> (source / <a href="common.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">29</td>
            <td class="headerCovTableEntry">48</td>
            <td class="headerCovTableEntryLo">60.4 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">13</td>
            <td class="headerCovTableEntry">18</td>
            <td class="headerCovTableEntryLo">72.2 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;boost/thread.hpp&gt;</a>
<span class="lineNum">       2 </span>            : #include &lt;glog/logging.h&gt;
<span class="lineNum">       3 </span>            : #include &lt;cmath&gt;
<span class="lineNum">       4 </span>            : #include &lt;cstdio&gt;
<span class="lineNum">       5 </span>            : #include &lt;ctime&gt;
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #include &quot;caffe/common.hpp&quot;
<span class="lineNum">       8 </span>            : #include &quot;caffe/util/rng.hpp&quot;
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : namespace caffe {
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : // Make sure each thread can have different values.
<a name="13"><span class="lineNum">      13 </span><span class="lineCov">          1 : static boost::thread_specific_ptr&lt;Caffe&gt; thread_instance_;</span></a>
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span><span class="lineCov">      32549 : Caffe&amp; Caffe::Get() {</span>
<span class="lineNum">      16 </span><span class="lineCov">      32550 :   if (!thread_instance_.get()) {</span>
<span class="lineNum">      17 </span><span class="lineCov">          2 :     thread_instance_.reset(new Caffe());</span>
<span class="lineNum">      18 </span>            :   }
<span class="lineNum">      19 </span><span class="lineCov">      32550 :   return *(thread_instance_.get());</span>
<span class="lineNum">      20 </span>            : }
<a name="21"><span class="lineNum">      21 </span>            : </a>
<span class="lineNum">      22 </span>            : // random seeding
<span class="lineNum">      23 </span><span class="lineCov">          1 : int64_t cluster_seedgen(void) {</span>
<span class="lineNum">      24 </span>            :   int64_t s, seed, pid;
<span class="lineNum">      25 </span><span class="lineCov">          1 :   FILE* f = fopen(&quot;/dev/urandom&quot;, &quot;rb&quot;);</span>
<span class="lineNum">      26 </span><span class="lineCov">          2 :   if (f &amp;&amp; fread(&amp;seed, 1, sizeof(seed), f) == sizeof(seed)) {</span>
<span class="lineNum">      27 </span><span class="lineCov">          1 :     fclose(f);</span>
<span class="lineNum">      28 </span><span class="lineCov">          1 :     return seed;</span>
<span class="lineNum">      29 </span>            :   }
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span><span class="lineNoCov">          0 :   LOG(INFO) &lt;&lt; &quot;System entropy source not available, &quot;</span>
<span class="lineNum">      32 </span><span class="lineNoCov">          0 :               &quot;using fallback algorithm to generate seed instead.&quot;;</span>
<span class="lineNum">      33 </span><span class="lineNoCov">          0 :   if (f)</span>
<span class="lineNum">      34 </span><span class="lineNoCov">          0 :     fclose(f);</span>
<span class="lineNum">      35 </span>            : 
<span class="lineNum">      36 </span><span class="lineNoCov">          0 :   pid = getpid();</span>
<span class="lineNum">      37 </span><span class="lineNoCov">          0 :   s = time(NULL);</span>
<span class="lineNum">      38 </span><span class="lineNoCov">          0 :   seed = std::abs(((s * 181) * ((pid - 83) * 359)) % 104729);</span>
<span class="lineNum">      39 </span><span class="lineNoCov">          0 :   return seed;</span>
<span class="lineNum">      40 </span>            : }
<a name="41"><span class="lineNum">      41 </span>            : </a>
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span><span class="lineCov">          1 : void GlobalInit(int* pargc, char*** pargv) {</span>
<span class="lineNum">      44 </span>            :   // Google flags.
<span class="lineNum">      45 </span><span class="lineCov">          1 :   ::gflags::ParseCommandLineFlags(pargc, pargv, true);</span>
<span class="lineNum">      46 </span>            :   // Google logging.
<span class="lineNum">      47 </span><span class="lineCov">          1 :   ::google::InitGoogleLogging(*(pargv)[0]);</span>
<span class="lineNum">      48 </span>            :   // Provide a backtrace on segfault.
<span class="lineNum">      49 </span><span class="lineCov">          1 :   ::google::InstallFailureSignalHandler();</span>
<span class="lineNum">      50 </span><span class="lineCov">          1 : }</span>
<span class="lineNum">      51 </span>            : 
<a name="52"><span class="lineNum">      52 </span>            : #ifdef CPU_ONLY  // CPU-only Caffe.</a>
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span><span class="lineCov">          2 : Caffe::Caffe()</span>
<span class="lineNum">      55 </span>            :     : random_generator_(), mode_(Caffe::CPU),
<a name="56"><span class="lineNum">      56 </span><span class="lineCov">          2 :       solver_count_(1), solver_rank_(0), multiprocess_(false) { }</span></a>
<span class="lineNum">      57 </span>            : 
<a name="58"><span class="lineNum">      58 </span><span class="lineCov">          4 : Caffe::~Caffe() { }</span></a>
<span class="lineNum">      59 </span>            : 
<span class="lineNum">      60 </span><span class="lineCov">          1 : void Caffe::set_random_seed(const unsigned int seed) {</span>
<span class="lineNum">      61 </span>            :   // RNG seed
<span class="lineNum">      62 </span><span class="lineCov">          1 :   Get().random_generator_.reset(new RNG(seed));</span>
<a name="63"><span class="lineNum">      63 </span><span class="lineCov">          1 : }</span></a>
<span class="lineNum">      64 </span>            : 
<span class="lineNum">      65 </span><span class="lineNoCov">          0 : void Caffe::SetDevice(const int device_id) {</span>
<span class="lineNum">      66 </span><span class="lineNoCov">          0 :   NO_GPU;</span>
<a name="67"><span class="lineNum">      67 </span>            : }</a>
<span class="lineNum">      68 </span>            : 
<span class="lineNum">      69 </span><span class="lineNoCov">          0 : void Caffe::DeviceQuery() {</span>
<span class="lineNum">      70 </span><span class="lineNoCov">          0 :   NO_GPU;</span>
<a name="71"><span class="lineNum">      71 </span>            : }</a>
<span class="lineNum">      72 </span>            : 
<span class="lineNum">      73 </span><span class="lineNoCov">          0 : bool Caffe::CheckDevice(const int device_id) {</span>
<span class="lineNum">      74 </span><span class="lineNoCov">          0 :   NO_GPU;</span>
<span class="lineNum">      75 </span>            :   return false;
<a name="76"><span class="lineNum">      76 </span>            : }</a>
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span><span class="lineNoCov">          0 : int Caffe::FindDevice(const int start_id) {</span>
<span class="lineNum">      79 </span><span class="lineNoCov">          0 :   NO_GPU;</span>
<span class="lineNum">      80 </span>            :   return -1;
<span class="lineNum">      81 </span>            : }
<span class="lineNum">      82 </span>            : 
<a name="83"><span class="lineNum">      83 </span><span class="lineCov">          2 : class Caffe::RNG::Generator {</span></a>
<a name="84"><span class="lineNum">      84 </span>            :  public:</a>
<span class="lineNum">      85 </span><span class="lineCov">          2 :   Generator() : rng_(new caffe::rng_t(cluster_seedgen())) {}</span>
<span class="lineNum">      86 </span><span class="lineCov">          2 :   explicit Generator(unsigned int seed) : rng_(new caffe::rng_t(seed)) {}</span>
<span class="lineNum">      87 </span>            :   caffe::rng_t* rng() { return rng_.get(); }
<span class="lineNum">      88 </span>            :  private:
<span class="lineNum">      89 </span>            :   shared_ptr&lt;caffe::rng_t&gt; rng_;
<a name="90"><span class="lineNum">      90 </span>            : };</a>
<span class="lineNum">      91 </span>            : 
<a name="92"><span class="lineNum">      92 </span><span class="lineCov">          1 : Caffe::RNG::RNG() : generator_(new Generator()) { }</span></a>
<span class="lineNum">      93 </span>            : 
<a name="94"><span class="lineNum">      94 </span><span class="lineCov">          1 : Caffe::RNG::RNG(unsigned int seed) : generator_(new Generator(seed)) { }</span></a>
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span><span class="lineNoCov">          0 : Caffe::RNG&amp; Caffe::RNG::operator=(const RNG&amp; other) {</span>
<span class="lineNum">      97 </span><span class="lineNoCov">          0 :   generator_ = other.generator_;</span>
<span class="lineNum">      98 </span><span class="lineNoCov">          0 :   return *this;</span>
<a name="99"><span class="lineNum">      99 </span>            : }</a>
<span class="lineNum">     100 </span>            : 
<span class="lineNum">     101 </span><span class="lineCov">          5 : void* Caffe::RNG::generator() {</span>
<span class="lineNum">     102 </span><span class="lineCov">          5 :   return static_cast&lt;void*&gt;(generator_-&gt;rng());</span>
<span class="lineNum">     103 </span>            : }
<span class="lineNum">     104 </span>            : 
<span class="lineNum">     105 </span>            : #else  // Normal GPU + CPU Caffe.
<span class="lineNum">     106 </span>            : 
<span class="lineNum">     107 </span>            : Caffe::Caffe()
<span class="lineNum">     108 </span>            :     : cublas_handle_(NULL), curand_generator_(NULL), random_generator_(),
<span class="lineNum">     109 </span>            :     mode_(Caffe::CPU),
<span class="lineNum">     110 </span>            :     solver_count_(1), solver_rank_(0), multiprocess_(false) {
<span class="lineNum">     111 </span>            :   // Try to create a cublas handler, and report an error if failed (but we will
<span class="lineNum">     112 </span>            :   // keep the program running as one might just want to run CPU code).
<span class="lineNum">     113 </span>            :   if (cublasCreate(&amp;cublas_handle_) != CUBLAS_STATUS_SUCCESS) {
<span class="lineNum">     114 </span>            :     LOG(ERROR) &lt;&lt; &quot;Cannot create Cublas handle. Cublas won't be available.&quot;;
<span class="lineNum">     115 </span>            :   }
<span class="lineNum">     116 </span>            :   // Try to create a curand handler.
<span class="lineNum">     117 </span>            :   if (curandCreateGenerator(&amp;curand_generator_, CURAND_RNG_PSEUDO_DEFAULT)
<span class="lineNum">     118 </span>            :       != CURAND_STATUS_SUCCESS ||
<span class="lineNum">     119 </span>            :       curandSetPseudoRandomGeneratorSeed(curand_generator_, cluster_seedgen())
<span class="lineNum">     120 </span>            :       != CURAND_STATUS_SUCCESS) {
<span class="lineNum">     121 </span>            :     LOG(ERROR) &lt;&lt; &quot;Cannot create Curand generator. Curand won't be available.&quot;;
<span class="lineNum">     122 </span>            :   }
<span class="lineNum">     123 </span>            : }
<span class="lineNum">     124 </span>            : 
<span class="lineNum">     125 </span>            : Caffe::~Caffe() {
<span class="lineNum">     126 </span>            :   if (cublas_handle_) CUBLAS_CHECK(cublasDestroy(cublas_handle_));
<span class="lineNum">     127 </span>            :   if (curand_generator_) {
<span class="lineNum">     128 </span>            :     CURAND_CHECK(curandDestroyGenerator(curand_generator_));
<span class="lineNum">     129 </span>            :   }
<span class="lineNum">     130 </span>            : }
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span>            : void Caffe::set_random_seed(const unsigned int seed) {
<span class="lineNum">     133 </span>            :   // Curand seed
<span class="lineNum">     134 </span>            :   static bool g_curand_availability_logged = false;
<span class="lineNum">     135 </span>            :   if (Get().curand_generator_) {
<span class="lineNum">     136 </span>            :     CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(curand_generator(),
<span class="lineNum">     137 </span>            :         seed));
<span class="lineNum">     138 </span>            :     CURAND_CHECK(curandSetGeneratorOffset(curand_generator(), 0));
<span class="lineNum">     139 </span>            :   } else {
<span class="lineNum">     140 </span>            :     if (!g_curand_availability_logged) {
<span class="lineNum">     141 </span>            :         LOG(ERROR) &lt;&lt;
<span class="lineNum">     142 </span>            :             &quot;Curand not available. Skipping setting the curand seed.&quot;;
<span class="lineNum">     143 </span>            :         g_curand_availability_logged = true;
<span class="lineNum">     144 </span>            :     }
<span class="lineNum">     145 </span>            :   }
<span class="lineNum">     146 </span>            :   // RNG seed
<span class="lineNum">     147 </span>            :   Get().random_generator_.reset(new RNG(seed));
<span class="lineNum">     148 </span>            : }
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            : void Caffe::SetDevice(const int device_id) {
<span class="lineNum">     151 </span>            :   int current_device;
<span class="lineNum">     152 </span>            :   CUDA_CHECK(cudaGetDevice(&amp;current_device));
<span class="lineNum">     153 </span>            :   if (current_device == device_id) {
<span class="lineNum">     154 </span>            :     return;
<span class="lineNum">     155 </span>            :   }
<span class="lineNum">     156 </span>            :   // The call to cudaSetDevice must come before any calls to Get, which
<span class="lineNum">     157 </span>            :   // may perform initialization using the GPU.
<span class="lineNum">     158 </span>            :   CUDA_CHECK(cudaSetDevice(device_id));
<span class="lineNum">     159 </span>            :   if (Get().cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().cublas_handle_));
<span class="lineNum">     160 </span>            :   if (Get().curand_generator_) {
<span class="lineNum">     161 </span>            :     CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_));
<span class="lineNum">     162 </span>            :   }
<span class="lineNum">     163 </span>            :   CUBLAS_CHECK(cublasCreate(&amp;Get().cublas_handle_));
<span class="lineNum">     164 </span>            :   CURAND_CHECK(curandCreateGenerator(&amp;Get().curand_generator_,
<span class="lineNum">     165 </span>            :       CURAND_RNG_PSEUDO_DEFAULT));
<span class="lineNum">     166 </span>            :   CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().curand_generator_,
<span class="lineNum">     167 </span>            :       cluster_seedgen()));
<span class="lineNum">     168 </span>            : }
<span class="lineNum">     169 </span>            : 
<span class="lineNum">     170 </span>            : void Caffe::DeviceQuery() {
<span class="lineNum">     171 </span>            :   cudaDeviceProp prop;
<span class="lineNum">     172 </span>            :   int device;
<span class="lineNum">     173 </span>            :   if (cudaSuccess != cudaGetDevice(&amp;device)) {
<span class="lineNum">     174 </span>            :     printf(&quot;No cuda device present.\n&quot;);
<span class="lineNum">     175 </span>            :     return;
<span class="lineNum">     176 </span>            :   }
<span class="lineNum">     177 </span>            :   CUDA_CHECK(cudaGetDeviceProperties(&amp;prop, device));
<span class="lineNum">     178 </span>            :   LOG(INFO) &lt;&lt; &quot;Device id:                     &quot; &lt;&lt; device;
<span class="lineNum">     179 </span>            :   LOG(INFO) &lt;&lt; &quot;Major revision number:         &quot; &lt;&lt; prop.major;
<span class="lineNum">     180 </span>            :   LOG(INFO) &lt;&lt; &quot;Minor revision number:         &quot; &lt;&lt; prop.minor;
<span class="lineNum">     181 </span>            :   LOG(INFO) &lt;&lt; &quot;Name:                          &quot; &lt;&lt; prop.name;
<span class="lineNum">     182 </span>            :   LOG(INFO) &lt;&lt; &quot;Total global memory:           &quot; &lt;&lt; prop.totalGlobalMem;
<span class="lineNum">     183 </span>            :   LOG(INFO) &lt;&lt; &quot;Total shared memory per block: &quot; &lt;&lt; prop.sharedMemPerBlock;
<span class="lineNum">     184 </span>            :   LOG(INFO) &lt;&lt; &quot;Total registers per block:     &quot; &lt;&lt; prop.regsPerBlock;
<span class="lineNum">     185 </span>            :   LOG(INFO) &lt;&lt; &quot;Warp size:                     &quot; &lt;&lt; prop.warpSize;
<span class="lineNum">     186 </span>            :   LOG(INFO) &lt;&lt; &quot;Maximum memory pitch:          &quot; &lt;&lt; prop.memPitch;
<span class="lineNum">     187 </span>            :   LOG(INFO) &lt;&lt; &quot;Maximum threads per block:     &quot; &lt;&lt; prop.maxThreadsPerBlock;
<span class="lineNum">     188 </span>            :   LOG(INFO) &lt;&lt; &quot;Maximum dimension of block:    &quot;
<span class="lineNum">     189 </span>            :       &lt;&lt; prop.maxThreadsDim[0] &lt;&lt; &quot;, &quot; &lt;&lt; prop.maxThreadsDim[1] &lt;&lt; &quot;, &quot;
<span class="lineNum">     190 </span>            :       &lt;&lt; prop.maxThreadsDim[2];
<span class="lineNum">     191 </span>            :   LOG(INFO) &lt;&lt; &quot;Maximum dimension of grid:     &quot;
<span class="lineNum">     192 </span>            :       &lt;&lt; prop.maxGridSize[0] &lt;&lt; &quot;, &quot; &lt;&lt; prop.maxGridSize[1] &lt;&lt; &quot;, &quot;
<span class="lineNum">     193 </span>            :       &lt;&lt; prop.maxGridSize[2];
<span class="lineNum">     194 </span>            :   LOG(INFO) &lt;&lt; &quot;Clock rate:                    &quot; &lt;&lt; prop.clockRate;
<span class="lineNum">     195 </span>            :   LOG(INFO) &lt;&lt; &quot;Total constant memory:         &quot; &lt;&lt; prop.totalConstMem;
<span class="lineNum">     196 </span>            :   LOG(INFO) &lt;&lt; &quot;Texture alignment:             &quot; &lt;&lt; prop.textureAlignment;
<span class="lineNum">     197 </span>            :   LOG(INFO) &lt;&lt; &quot;Concurrent copy and execution: &quot;
<span class="lineNum">     198 </span>            :       &lt;&lt; (prop.deviceOverlap ? &quot;Yes&quot; : &quot;No&quot;);
<span class="lineNum">     199 </span>            :   LOG(INFO) &lt;&lt; &quot;Number of multiprocessors:     &quot; &lt;&lt; prop.multiProcessorCount;
<span class="lineNum">     200 </span>            :   LOG(INFO) &lt;&lt; &quot;Kernel execution timeout:      &quot;
<span class="lineNum">     201 </span>            :       &lt;&lt; (prop.kernelExecTimeoutEnabled ? &quot;Yes&quot; : &quot;No&quot;);
<span class="lineNum">     202 </span>            :   return;
<span class="lineNum">     203 </span>            : }
<span class="lineNum">     204 </span>            : 
<span class="lineNum">     205 </span>            : bool Caffe::CheckDevice(const int device_id) {
<span class="lineNum">     206 </span>            :   // This function checks the availability of GPU #device_id.
<span class="lineNum">     207 </span>            :   // It attempts to create a context on the device by calling cudaFree(0).
<span class="lineNum">     208 </span>            :   // cudaSetDevice() alone is not sufficient to check the availability.
<span class="lineNum">     209 </span>            :   // It lazily records device_id, however, does not initialize a
<span class="lineNum">     210 </span>            :   // context. So it does not know if the host thread has the permission to use
<span class="lineNum">     211 </span>            :   // the device or not.
<span class="lineNum">     212 </span>            :   //
<span class="lineNum">     213 </span>            :   // In a shared environment where the devices are set to EXCLUSIVE_PROCESS
<span class="lineNum">     214 </span>            :   // or EXCLUSIVE_THREAD mode, cudaSetDevice() returns cudaSuccess
<span class="lineNum">     215 </span>            :   // even if the device is exclusively occupied by another process or thread.
<span class="lineNum">     216 </span>            :   // Cuda operations that initialize the context are needed to check
<span class="lineNum">     217 </span>            :   // the permission. cudaFree(0) is one of those with no side effect,
<span class="lineNum">     218 </span>            :   // except the context initialization.
<span class="lineNum">     219 </span>            :   bool r = ((cudaSuccess == cudaSetDevice(device_id)) &amp;&amp;
<span class="lineNum">     220 </span>            :             (cudaSuccess == cudaFree(0)));
<span class="lineNum">     221 </span>            :   // reset any error that may have occurred.
<span class="lineNum">     222 </span>            :   cudaGetLastError();
<span class="lineNum">     223 </span>            :   return r;
<span class="lineNum">     224 </span>            : }
<span class="lineNum">     225 </span>            : 
<span class="lineNum">     226 </span>            : int Caffe::FindDevice(const int start_id) {
<span class="lineNum">     227 </span>            :   // This function finds the first available device by checking devices with
<span class="lineNum">     228 </span>            :   // ordinal from start_id to the highest available value. In the
<span class="lineNum">     229 </span>            :   // EXCLUSIVE_PROCESS or EXCLUSIVE_THREAD mode, if it succeeds, it also
<span class="lineNum">     230 </span>            :   // claims the device due to the initialization of the context.
<span class="lineNum">     231 </span>            :   int count = 0;
<span class="lineNum">     232 </span>            :   CUDA_CHECK(cudaGetDeviceCount(&amp;count));
<span class="lineNum">     233 </span>            :   for (int i = start_id; i &lt; count; i++) {
<span class="lineNum">     234 </span>            :     if (CheckDevice(i)) return i;
<span class="lineNum">     235 </span>            :   }
<span class="lineNum">     236 </span>            :   return -1;
<span class="lineNum">     237 </span>            : }
<span class="lineNum">     238 </span>            : 
<span class="lineNum">     239 </span>            : class Caffe::RNG::Generator {
<span class="lineNum">     240 </span>            :  public:
<span class="lineNum">     241 </span>            :   Generator() : rng_(new caffe::rng_t(cluster_seedgen())) {}
<span class="lineNum">     242 </span>            :   explicit Generator(unsigned int seed) : rng_(new caffe::rng_t(seed)) {}
<span class="lineNum">     243 </span>            :   caffe::rng_t* rng() { return rng_.get(); }
<span class="lineNum">     244 </span>            :  private:
<span class="lineNum">     245 </span>            :   shared_ptr&lt;caffe::rng_t&gt; rng_;
<span class="lineNum">     246 </span>            : };
<span class="lineNum">     247 </span>            : 
<span class="lineNum">     248 </span>            : Caffe::RNG::RNG() : generator_(new Generator()) { }
<span class="lineNum">     249 </span>            : 
<span class="lineNum">     250 </span>            : Caffe::RNG::RNG(unsigned int seed) : generator_(new Generator(seed)) { }
<span class="lineNum">     251 </span>            : 
<span class="lineNum">     252 </span>            : Caffe::RNG&amp; Caffe::RNG::operator=(const RNG&amp; other) {
<span class="lineNum">     253 </span>            :   generator_.reset(other.generator_.get());
<span class="lineNum">     254 </span>            :   return *this;
<span class="lineNum">     255 </span>            : }
<span class="lineNum">     256 </span>            : 
<span class="lineNum">     257 </span>            : void* Caffe::RNG::generator() {
<span class="lineNum">     258 </span>            :   return static_cast&lt;void*&gt;(generator_-&gt;rng());
<span class="lineNum">     259 </span>            : }
<span class="lineNum">     260 </span>            : 
<span class="lineNum">     261 </span>            : const char* cublasGetErrorString(cublasStatus_t error) {
<span class="lineNum">     262 </span>            :   switch (error) {
<span class="lineNum">     263 </span>            :   case CUBLAS_STATUS_SUCCESS:
<span class="lineNum">     264 </span>            :     return &quot;CUBLAS_STATUS_SUCCESS&quot;;
<span class="lineNum">     265 </span>            :   case CUBLAS_STATUS_NOT_INITIALIZED:
<span class="lineNum">     266 </span>            :     return &quot;CUBLAS_STATUS_NOT_INITIALIZED&quot;;
<span class="lineNum">     267 </span>            :   case CUBLAS_STATUS_ALLOC_FAILED:
<span class="lineNum">     268 </span>            :     return &quot;CUBLAS_STATUS_ALLOC_FAILED&quot;;
<span class="lineNum">     269 </span>            :   case CUBLAS_STATUS_INVALID_VALUE:
<span class="lineNum">     270 </span>            :     return &quot;CUBLAS_STATUS_INVALID_VALUE&quot;;
<span class="lineNum">     271 </span>            :   case CUBLAS_STATUS_ARCH_MISMATCH:
<span class="lineNum">     272 </span>            :     return &quot;CUBLAS_STATUS_ARCH_MISMATCH&quot;;
<span class="lineNum">     273 </span>            :   case CUBLAS_STATUS_MAPPING_ERROR:
<span class="lineNum">     274 </span>            :     return &quot;CUBLAS_STATUS_MAPPING_ERROR&quot;;
<span class="lineNum">     275 </span>            :   case CUBLAS_STATUS_EXECUTION_FAILED:
<span class="lineNum">     276 </span>            :     return &quot;CUBLAS_STATUS_EXECUTION_FAILED&quot;;
<span class="lineNum">     277 </span>            :   case CUBLAS_STATUS_INTERNAL_ERROR:
<span class="lineNum">     278 </span>            :     return &quot;CUBLAS_STATUS_INTERNAL_ERROR&quot;;
<span class="lineNum">     279 </span>            : #if CUDA_VERSION &gt;= 6000
<span class="lineNum">     280 </span>            :   case CUBLAS_STATUS_NOT_SUPPORTED:
<span class="lineNum">     281 </span>            :     return &quot;CUBLAS_STATUS_NOT_SUPPORTED&quot;;
<span class="lineNum">     282 </span>            : #endif
<span class="lineNum">     283 </span>            : #if CUDA_VERSION &gt;= 6050
<span class="lineNum">     284 </span>            :   case CUBLAS_STATUS_LICENSE_ERROR:
<span class="lineNum">     285 </span>            :     return &quot;CUBLAS_STATUS_LICENSE_ERROR&quot;;
<span class="lineNum">     286 </span>            : #endif
<span class="lineNum">     287 </span>            :   }
<span class="lineNum">     288 </span>            :   return &quot;Unknown cublas status&quot;;
<span class="lineNum">     289 </span>            : }
<span class="lineNum">     290 </span>            : 
<span class="lineNum">     291 </span>            : const char* curandGetErrorString(curandStatus_t error) {
<span class="lineNum">     292 </span>            :   switch (error) {
<span class="lineNum">     293 </span>            :   case CURAND_STATUS_SUCCESS:
<span class="lineNum">     294 </span>            :     return &quot;CURAND_STATUS_SUCCESS&quot;;
<span class="lineNum">     295 </span>            :   case CURAND_STATUS_VERSION_MISMATCH:
<span class="lineNum">     296 </span>            :     return &quot;CURAND_STATUS_VERSION_MISMATCH&quot;;
<span class="lineNum">     297 </span>            :   case CURAND_STATUS_NOT_INITIALIZED:
<span class="lineNum">     298 </span>            :     return &quot;CURAND_STATUS_NOT_INITIALIZED&quot;;
<span class="lineNum">     299 </span>            :   case CURAND_STATUS_ALLOCATION_FAILED:
<span class="lineNum">     300 </span>            :     return &quot;CURAND_STATUS_ALLOCATION_FAILED&quot;;
<span class="lineNum">     301 </span>            :   case CURAND_STATUS_TYPE_ERROR:
<span class="lineNum">     302 </span>            :     return &quot;CURAND_STATUS_TYPE_ERROR&quot;;
<span class="lineNum">     303 </span>            :   case CURAND_STATUS_OUT_OF_RANGE:
<span class="lineNum">     304 </span>            :     return &quot;CURAND_STATUS_OUT_OF_RANGE&quot;;
<span class="lineNum">     305 </span>            :   case CURAND_STATUS_LENGTH_NOT_MULTIPLE:
<span class="lineNum">     306 </span>            :     return &quot;CURAND_STATUS_LENGTH_NOT_MULTIPLE&quot;;
<span class="lineNum">     307 </span>            :   case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED:
<span class="lineNum">     308 </span>            :     return &quot;CURAND_STATUS_DOUBLE_PRECISION_REQUIRED&quot;;
<span class="lineNum">     309 </span>            :   case CURAND_STATUS_LAUNCH_FAILURE:
<span class="lineNum">     310 </span>            :     return &quot;CURAND_STATUS_LAUNCH_FAILURE&quot;;
<span class="lineNum">     311 </span>            :   case CURAND_STATUS_PREEXISTING_FAILURE:
<span class="lineNum">     312 </span>            :     return &quot;CURAND_STATUS_PREEXISTING_FAILURE&quot;;
<span class="lineNum">     313 </span>            :   case CURAND_STATUS_INITIALIZATION_FAILED:
<span class="lineNum">     314 </span>            :     return &quot;CURAND_STATUS_INITIALIZATION_FAILED&quot;;
<span class="lineNum">     315 </span>            :   case CURAND_STATUS_ARCH_MISMATCH:
<span class="lineNum">     316 </span>            :     return &quot;CURAND_STATUS_ARCH_MISMATCH&quot;;
<span class="lineNum">     317 </span>            :   case CURAND_STATUS_INTERNAL_ERROR:
<span class="lineNum">     318 </span>            :     return &quot;CURAND_STATUS_INTERNAL_ERROR&quot;;
<span class="lineNum">     319 </span>            :   }
<span class="lineNum">     320 </span>            :   return &quot;Unknown curand status&quot;;
<span class="lineNum">     321 </span>            : }
<span class="lineNum">     322 </span>            : 
<a name="323"><span class="lineNum">     323 </span>            : #endif  // CPU_ONLY</a>
<span class="lineNum">     324 </span>            : 
<span class="lineNum">     325 </span><span class="lineCov">          3 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
